library(dplyr)
library(estimatr)

## Make a data set for analysis dropping unmatched people and
## pairs with identical perceptions (subj_rank==.5)
analysisdat <- maindata %>%
  filter(!is.na(pairidx)) %>%
  group_by(pairidx) %>%
  mutate(
    subj_rank = rank(community_perception) - 1,
    social_cohesion_rank = rank(social_cohesion) - 1,
    community_efficacy_rank = rank(community_efficacy) - 1
  ) %>%
  filter(subj_rank != .5) %>%
  droplevels() %>%
  ungroup()

fe_est <- lm_robust(social_cohesion ~ community_perception + objective_pct_vm_DA,
  fixed.effects = ~pairidx, data = analysisdat
)
